﻿// -----------------------------------------------------------------------
// <copyright file="CommonPluralRules.cs" company="Moveax, LLC">
// Copyright (c) 2013 Andrey Veselov. All rights reserved.
// License:  Microsoft Public License (MS-PL)
// Contacts: http://andrey.moveax.com andrey@moveax.com
// </copyright>
// -----------------------------------------------------------------------

namespace Moveax.Pluralization.Core.LanguageRules
{
    using System;

    /// <summary>Language plural rules for: Afrikaans, Albanian, Asu, Basque, Bemba, Bena, Bengali, Bodo, Bulgarian, Catalan, Cherokee, Chiga, Danish, Divehi, Dutch, 
    /// English, Esperanto, Estonian, Ewe, Faroese, Finnish, Friulian, Galician, Ganda, German, Greek, Gujarati, Hausa, Hawaiian, Hebrew, 
    /// Icelandic, Italian, Jju, Kalaallisut, Kazakh, Kurdish, Luxembourgish, Machame, Malayalam, Marathi, Masai, Mongolian, Nahuatl, 
    /// Nepali, North Ndebele, Norwegian, Norwegian Bokmål, Norwegian Nynorsk, Nyanja, Nyankole, Oriya, Oromo, Papiamento, Pashto, 
    /// Portuguese, Punjabi, Romansh, Rombo, Rwa, Saho, Samburu, Sena, Shambala, Shona, Soga, Somali, South Ndebele, Southern Sotho, 
    /// Spanish, Swahili, Swati, Swedish, Swiss German, Syriac, Tamil, Telugu, Teso, Tigre, Tsonga, Tswana, Turkmen, Tyap, Urdu, Venda, Vunjo, 
    /// Walser, Western Frisian, Xhosa, Zulu.</summary>
    internal class CommonPluralRules : IPluralRules
    {
        public CommonPluralRules(string languageCode)
        {
            if (string.IsNullOrEmpty(languageCode))
                throw new ArgumentNullException("languageCode");

            this.LanguageCode = languageCode;
        }

        public string LanguageCode { get; private set; }

        public virtual PluralCategory GetCategoryFor(int value)
        {
            int absValue = Math.Abs(value);

            return absValue == 1 ?
                PluralCategory.One :
                PluralCategory.Other;
        }

        public virtual PluralCategory GetCategoryFor(float value)
        {
            bool isInteger = (value % 1).Equals(0.0f);

            return isInteger ?
                this.GetCategoryFor((int)value) :
                PluralCategory.Other;
        }
    }
}